package cn.getech.data.development.constant;

import lombok.Getter;

/**
 * @description: 任务运行状态
 * @author: wangzhaowen：kiss
 * @create: 2020/9/18 16:25
 * @version: 2020/9/18
 **/
@Getter
public enum RunStatus {
    //0 失败 1 成功 2 运行中 3 未运行
    WAIT(3, "未运行"),
    FAIL(0, "失败"),
    SUCCESS(1, "成功"),
    RUNNING(2, "运行中"),
    KILLED(4, "停止"),
    NEW(3,"NEW"),
    NEW_SAVING(3,"NEW_SAVING"),
    SUBMITTED(2,"SUBMITTED"),
    ACCEPTED(2,"ACCEPTED"),
    RUNNING_(2,"RUNNING"),
    FINISHED(1,"FINISHED"),
    FAILED(0,"FAILED"),
    KILLED_(4,"KILLED"),
    ;
    Integer status;
    String desc;

    RunStatus(Integer status, String desc) {
        this.status = status;
        this.desc = desc;
    }

    /**
     * yarn 状态转换成本系统的状态
     * @param key 运行状态
     */
    public static Integer getStatus(String key) {
        for (RunStatus value : RunStatus.values()) {
            if (value.getDesc().equals(key)) {
                return value.getStatus();
            }
        }
        return 0;
    }

    public static String getStatusDesc(Integer key) {
        for (RunStatus value : RunStatus.values()) {
            if (value.getStatus().equals(key)) {
                return value.getDesc();
            }
        }
        return null;
    }
}
